{extend name="ace/layout/master/detail" /}

{block name="title"}配置管理{/block}
{block name="page-title"}配置{/block}

{block name="style"}
<style>
    textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"]{
        line-height: inherit;
    }
</style>
{/block}

{block name="content"}
    <input name="config_id" class="form-control" type="hidden" value="{if $detail}{$detail->config_id}{/if}" />
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right"> 配置标题：</label>
        <div class="col-sm-9">
            <input type="text" name="config_title" placeholder="输入配置标题" class="col-xs-10 col-sm-5" required="" value="{if $detail}{$detail->config_title}{/if}" />
            <span class="lbl col-xs-12 col-sm-7">
                <i class="icon-info-sign"></i> 唯一标识
            </span>
        </div>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right"> 配置名称：</label>
        <div class="col-sm-9">
            <input type="text" name="config_name" placeholder="输入配置名称" class="col-xs-10 col-sm-5" required="" value="{if $detail}{$detail->config_name}{/if}" />
            <span class="lbl col-xs-12 col-sm-7">
                <i class="icon-info-sign"></i> 英文字符串
            </span>
        </div>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right"> 配置类型：</label>
        <div class="col-sm-9 roles_ary">
            <select name="config_type" class="col-xs-10 col-sm-5" required onchange="config_type_change(this)">
                <option value="0"> 请选择类型 </option>
                {if !empty($config_type_list)}
                    {foreach $config_type_list as $key => $config_type}
                        <option value="{$key}" {if ($detail && $key === $detail->config_type)}selected{/if}> {$config_type} </option>
                    {/foreach}
                {/if}
            </select>
            <span class="lbl col-xs-12 col-sm-7">
                <i class="icon-info-sign"></i> 系统会根据不同类型解析配置值
            </span>
        </div>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right"> 配置分组：</label>
        <div class="col-sm-9 roles_ary">
            <select name="config_group" class="col-xs-10 col-sm-5" required>
                <option value="0"> 请选择分组 </option>
                {if !empty($config_group_list)}
                    {foreach $config_group_list as $key => $config_group}
                    <option value="{$key}" {if ($detail && $key === $detail->config_group)}selected{/if} > {$config_group} </option>
                    {/foreach}
                {/if}
            </select>
            <span class="lbl col-xs-12 col-sm-7">
                <i class="icon-info-sign"></i> 用于区分展示列表
            </span>
        </div>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right"> 配置值：</label>
        <div class="col-sm-9 config-value-html">
            {if $detail && $detail->config_type == 6 }
            <script id="ue-container" name="config_value" type="text/plain">{if $detail}{:htmlspecialchars_decode($detail->config_value)}{/if}</script>
            {else /}
            <textarea name="config_value" class="col-xs-10 col-sm-5">{if $detail}{:htmlspecialchars_decode($detail->config_value)}{/if}</textarea>
            {/if}
        </div>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right"> 配置项：</label>
        <div class="col-sm-9">
            <textarea name="config_extra" class="col-xs-10 col-sm-5">{if $detail}{$detail->config_extra}{/if}</textarea>
            <span class="lbl col-xs-12 col-sm-7">
                <i class="icon-info-sign"></i> 如果是枚举型，需要配置该项
            </span>
        </div>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right"> 排序：</label>
        <div class="col-sm-9">
            <input type="number" name="config_sort" class="col-xs-10 col-sm-5" required="" value="{if $detail}{$detail->config_sort}{/if}" />
        </div>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right"> 备注：</label>
        <div class="col-sm-9">
            <textarea name="config_remarks" class="col-xs-10 col-sm-5">{if $detail}{$detail->config_remarks}{/if}</textarea>
            <span class="lbl col-xs-12 col-sm-7">
                <i class="icon-info-sign"></i> 配置项的具体说明详情
            </span>
        </div>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right">
            是否启用：
            <br/>
            <small class="green"><b>启用</b></small>
            才生效可用
        </label>
        <div class="col-sm-9 radio">
            <label>
                <input name="is_check" type="radio" class="ace" value="1" {if (empty($detail) || $detail->is_check === 1) }checked{/if} />
                <span class="lbl"> 启用 </span>
            </label>
            <label>
                <input name="is_check" type="radio" class="ace" value="0" {if (empty($detail) || $detail->is_check === 0) }checked{/if} />
                <span class="lbl"> 禁用 </span>
            </label>
        </div>
    </div>
{/block}

{block name="script"}
{include file="ace/layout:ueditor" /}
<script type="text/javascript">
    window.onload = function () {
        closeLayerLoading(closeAllLayer);

        var res = JSON.parse('<?=html_get_res_from_admin($detail)?>');

        if (res && res.config_type == 6){
            createEditor();
        }
    }

    function config_type_change(_this) {
        str = '{if $detail}<?=html_get_res_from_admin(htmlspecialchars_decode($detail->config_value))?>{/if}';
        console.log(parseInt($(_this).val()));
        switch (parseInt($(_this).val())) {
            case 6: // 富文本
                $('.config-value-html').html('<script id="ue-container" name="config_value" type="text/plain">' + str + '<\/script>');
                createEditor();
                break;
            default:
                $('.config-value-html').html('<textarea name="config_value" class="col-xs-10 col-sm-5">' + str + '</textarea>');
                break;
        }
    }
</script>
{/block}